package com.box.mapper;

import com.box.entity.BlogTypeEntity;
import com.box.entity.DbBlog;
import com.box.entity.DbBlogExample;


import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


public interface DbBlogMapper {
    int countByExample(DbBlogExample example);

    int deleteByExample(DbBlogExample example);

    int deleteByPrimaryKey(Integer id);

    int insert(DbBlog record);

    int insertSelective(DbBlog record);

    List<DbBlog> selectByExampleWithBLOBs(DbBlogExample example);

    List<DbBlog> selectByExample(DbBlogExample example);

    DbBlog selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") DbBlog record, @Param("example") DbBlogExample example);

    int updateByExampleWithBLOBs(@Param("record") DbBlog record, @Param("example") DbBlogExample example);

    int updateByExample(@Param("record") DbBlog record, @Param("example") DbBlogExample example);

    int updateByPrimaryKeySelective(DbBlog record);

    int updateByPrimaryKeyWithBLOBs(DbBlog record);

    int updateByPrimaryKey(DbBlog record);
    
    @Select("SELECT * FROM db_blog WHERE uppid=2  GROUP BY clickHit ORDER BY clickHit DESC")
    List<DbBlog> selBlogListByClickHit();
    
    
    //===============
    @Select("SELECT * FROM db_blog b LEFT JOIN db_btype bt ON bt.tid=b.typeId WHERE b.uppid=2 ORDER BY  b.leaseDaet DESC limit #{firstIndex},#{pageNum} ")
    List<BlogTypeEntity> selBlogTypeALLTable(@Param("firstIndex") int firstIndex,@Param("pageNum") int pageNum);

    @Select("SELECT COUNT(*) FROM db_blog b LEFT JOIN db_btype bt ON bt.tid=b.typeId WHERE b.uppid=2")
    Long selCountByDbBlogAndType();
    //===============
    
    //根据博客类型ID查询对应字段连表查询可重复使用
    @Select("SELECT * FROM db_blog b LEFT JOIN db_btype bt ON bt.tid=b.typeId WHERE b.typeId=#{typeId} AND b.uppid=2 ORDER BY  b.leaseDaet DESC limit #{firstIndex},#{pageNum} ")
    List<BlogTypeEntity> selBlogTypeALLTableByBlog(@Param("typeId") int typeId,@Param("firstIndex") int firstIndex,@Param("pageNum") int pageNum);

    @Select("SELECT COUNT(*) FROM db_blog b LEFT JOIN db_btype bt ON bt.tid=b.typeId WHERE b.typeId=#{typeId} AND b.uppid=2 ")
    Long selCountByDbBlogAndTypeByBlog(@Param("typeId") int typeId);
    
    @Select("SELECT * FROM db_blog b LEFT JOIN db_btype bt ON bt.tid=b.typeId WHERE b.typeId=#{typeId} AND b.uppid=2 ORDER BY  b.leaseDaet DESC")
    List<BlogTypeEntity> selBlogTypeNewsTagByTypeId(@Param("typeId") int typeId);
    
    //查询单条数据
    @Select("SELECT * FROM db_blog b LEFT JOIN db_btype bt ON bt.tid=b.typeId WHERE b.id=#{id};")
    BlogTypeEntity selBlogByOne(@Param("id") Integer id);
    

}